package com.gisquest.rdsuse.mysql.scheduler;

import com.gisquest.rdsuse.mysql.config.RdsUsageConfig;
import com.gisquest.rdsuse.mysql.mapper.SearchMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 内存占用任务
 * @Author: lupy
 * @Date: 2019-11-20
 **/
@Component
@Slf4j
public class MemoryScheduledService {

	@Resource
	private SearchMapper searchMapper;

	@Resource
	private RdsUsageConfig usageConfig;

	/**
	 *暂未实现
	 */
	//@Scheduled(cron = "0 0/1 * * * ?")
	@Transactional(rollbackFor = Exception.class)
	public void closeMonthSwitch(){
		log.info("内存占用开始");
		int memorySize = usageConfig.getMemorySize();
		if (memorySize < 1) {
			log.info("内存占用取消");
			return;
		}
		String sql = "SELECT count(*) FROM (SELECT * FROM add_rds_usage_num limit "+ memorySize +") a  CROSS JOIN (SELECT * FROM add_rds_usage LIMIT 1) b";
		Object select = searchMapper.selectBySql(sql);
		log.info(sql);
	}
}
